import Vue from 'vue'
import {isMapEmpty, isNull, isNumber} from "@/util/common-util";

Vue.filter("defaultValue", (value) => {
  if (isNull(value)) return '--'
  return value
})

Vue.filter("kg2Tons", (value) => {
  return kg2Tons(value)
})

Vue.filter("tons2Kg", (value) => {
    return tons2Kg(value)
})

Vue.filter("shareBucket", (value) => {
  if (isNull(value)) return ''
  return "已并"
})

export function tons2Kg(value) {
    if (isNull(value)) return '--'
    try {
        return (Number(value) * 1000).toFixed(2)
    } catch (e) {
        console.error(e, value)
        return '-'
    }
}


export function kg2Tons(value) {
  if (isNull(value)) return '--'
  try {
    return (Number(value) / 1000).toFixed(2)
  } catch (e) {
    console.error(e, value)
    return '-'
  }
}


export const dictLabelMap = {}
let btnPermission = {}

export function initBtnPermission(v) {
  if (isMapEmpty(btnPermission)) btnPermission = {...v}
}

export function getBtnPermission() {
  return btnPermission
}
